package dashboard

import (
	"gitcode.com/G-YT/iHealth25/server/global"
	"gitcode.com/G-YT/iHealth25/server/model/common/response"
	userReq "gitcode.com/G-YT/iHealth25/server/model/user/request"
	"gitcode.com/G-YT/iHealth25/server/utils"
	"github.com/gin-gonic/gin"
	"go.uber.org/zap"
	"strconv"
)

type BordApi struct {
}

// GetAllUserData 获取全部用户数据大屏【超管】
// @Tags bord
// @Summary 获取全部用户数据大屏【超管】
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data query user.User true "获取全部用户数据大屏【超管】"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"查询成功"}"
// @Router /adminUser/GetAllUserData [get]
func (s *BordApi) GetAllUserData(c *gin.Context) {
	id := c.Query("id")
	ScID, _ := strconv.Atoi(id)
	if bord, err := BordServiceApp.GetAllUserData(uint(ScID)); err != nil {
		global.GVA_LOG.Error("获取失败!", zap.Error(err))
		response.FailWithMessage(err.Error(), c)
	} else {
		response.OkWithData(bord, c)
	}
}

// GetScUserData 获取全部用户数据大屏【服务中心】
// @Tags bord
// @Summary 获取全部用户数据大屏【服务中心】
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data query user.User true "获取全部用户数据大屏【服务中心】"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"查询成功"}"
// @Router /adminUser/GetAllUserData [get]
func (s *BordApi) GetScUserData(c *gin.Context) {
	centreID := utils.GetUserID(c)
	if bord, err := BordServiceApp.GetScUserData(centreID); err != nil {
		global.GVA_LOG.Error("获取失败!", zap.Error(err))
		response.FailWithMessage(err.Error(), c)
	} else {
		response.OkWithData(bord, c)
	}
}

// User 获取全部用户数据大屏【服务站】
func (s *BordApi) User(c *gin.Context) {
	idA := c.Query("id")
	IDA, _ := strconv.Atoi(idA)
	idB := utils.GetUserID(c)
	finalParam := idB
	if IDA != 0 {
		finalParam = uint(IDA)
	}
	if bord, err := BordServiceApp.User(finalParam); err != nil {
		global.GVA_LOG.Error("获取失败!", zap.Error(err))
		response.FailWithMessage(err.Error(), c)
	} else {
		response.OkWithData(bord, c)
	}
}

// GetAllStewardData 获取全部健管师数据大屏【超管】
// @Tags bord
// @Summary 获取全部健管师数据大屏【超管】
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data query user.User true "获取全部健管师数据大屏【超管】"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"查询成功"}"
// @Router /adminUser/getAllStewardData [get]
func (s *BordApi) GetAllStewardData(c *gin.Context) {
	if bord, err := BordServiceApp.GetAllStewardData(); err != nil {
		global.GVA_LOG.Error("获取失败!", zap.Error(err))
		response.FailWithMessage(err.Error(), c)
	} else {
		response.OkWithData(bord, c)
	}
}

// GetScStewardData 获取全部服务中心数据大屏【服务中心】
// @Tags bord
// @Summary 获取全部服务中心数据大屏【服务中心】
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data query user.User true "获取全部服务中心数据大屏【服务中心】"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"查询成功"}"
// @Router /adminUser/getScStewardData [get]
func (s *BordApi) GetScStewardData(c *gin.Context) {
	centreID := utils.GetUserID(c)
	if bord, err := BordServiceApp.GetScStewardData(centreID); err != nil {
		global.GVA_LOG.Error("获取失败!", zap.Error(err))
		response.FailWithMessage(err.Error(), c)
	} else {
		response.OkWithData(bord, c)
	}
}

// Steward 获取服务站健管师数据大屏【服务站】
func (s *BordApi) Steward(c *gin.Context) {
	idA := c.Query("id")
	IDA, _ := strconv.Atoi(idA)
	idB := utils.GetUserID(c)
	finalParam := idB
	if IDA != 0 {
		finalParam = uint(IDA)
	}
	if bord, err := BordServiceApp.Steward(finalParam); err != nil {
		global.GVA_LOG.Error("获取失败!", zap.Error(err))
		response.FailWithMessage(err.Error(), c)
	} else {
		response.OkWithData(bord, c)
	}
}

// GetDailyNewUsers 获取每日新增用户[健管师端]
func (s *BordApi) GetDailyNewUsers(c *gin.Context) {
	id := utils.GetHmID(c)
	if result, err := BordServiceApp.GetDailyNewUsers(id); err != nil {
		global.GVA_LOG.Error("获取失败!", zap.Error(err))
		response.FailWithMessage("获取成功", c)
	} else {
		response.OkWithDetailed(result, "获取成功", c)
	}
}

// GetDayNewUserList 获取当日新增用户列表[健管师端]
func (s *BordApi) GetDayNewUserList(c *gin.Context) {
	var pageInfo userReq.UserSearch
	err := c.ShouldBindQuery(&pageInfo)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	id := utils.GetHmID(c)
	pageInfo.StewardID = id
	if list, total, err := BordServiceApp.GetDayNewUserList(pageInfo); err != nil {
		global.GVA_LOG.Error("获取失败!", zap.Error(err))
		response.FailWithMessage("获取成功", c)
	} else {
		response.OkWithDetailed(response.PageResult{
			List:     list,
			Total:    total,
			Page:     pageInfo.Page,
			PageSize: pageInfo.PageSize,
		}, "获取成功", c)
	}
}

// GetUserData 获取用户数据[健管师端]
func (s *BordApi) GetUserData(c *gin.Context) {
	id := utils.GetHmID(c)
	if result, err := BordServiceApp.GetUserData(id); err != nil {
		global.GVA_LOG.Error("获取失败!", zap.Error(err))
		response.FailWithMessage("获取成功", c)
	} else {
		response.OkWithDetailed(result, "获取成功", c)
	}
}

// GetSexAndAgeRatio 获取性别年龄占比[健管师端]
func (s *BordApi) GetSexAndAgeRatio(c *gin.Context) {
	id := utils.GetHmID(c)
	if result, err := BordServiceApp.GetSexAndAgeRatio(id); err != nil {
		global.GVA_LOG.Error("获取失败!", zap.Error(err))
		response.FailWithMessage("获取成功", c)
	} else {
		response.OkWithDetailed(result, "获取成功", c)
	}
}

// GetDiseaseTop 获取病症TOP10
func (s *BordApi) GetDiseaseTop(c *gin.Context) {
	id := utils.GetHmID(c)
	if result, err := BordServiceApp.GetDiseaseTop(id); err != nil {
		global.GVA_LOG.Error("获取失败!", zap.Error(err))
		response.FailWithMessage("获取成功", c)
	} else {
		response.OkWithDetailed(result, "获取成功", c)
	}
}

// GetDiseaseUserList 获取病症用户列表
func (s *BordApi) GetDiseaseUserList(c *gin.Context) {
	id := c.Query("id")
	HmId := utils.GetHmID(c)
	if result, err := BordServiceApp.GetDiseaseUserList(HmId, id); err != nil {
		global.GVA_LOG.Error("获取失败!", zap.Error(err))
		response.FailWithMessage(err.Error(), c)
	} else {
		response.OkWithDetailed(result, "获取成功", c)
	}
}

// GetDayServiceNum 获取方案完成信息
func (s *BordApi) GetDayServiceNum(c *gin.Context) {
	HmId := utils.GetHmID(c)
	if result, err := BordServiceApp.GetDayServiceNum(HmId); err != nil {
		global.GVA_LOG.Error("获取失败!", zap.Error(err))
		response.FailWithMessage("获取失败!", c)
	} else {
		response.OkWithDetailed(result, "获取成功", c)
	}
}

// GetPlanCompleteInfo 获取今日服务人数
func (s *BordApi) GetPlanCompleteInfo(c *gin.Context) {
	HmId := utils.GetHmID(c)
	if result, err := BordServiceApp.GetPlanCompleteInfo(HmId); err != nil {
		global.GVA_LOG.Error("获取失败!", zap.Error(err))
		response.FailWithMessage(err.Error(), c)
	} else {
		response.OkWithDetailed(result, "获取成功", c)
	}
}

// GetHealthRecords 获取健康档案
func (s *BordApi) GetHealthRecords(c *gin.Context) {
	ID := c.Query("id")
	if result, err := BordServiceApp.GetHealthRecords(ID); err != nil {
		global.GVA_LOG.Error("获取失败!", zap.Error(err))
		response.FailWithMessage(err.Error(), c)
	} else {
		response.OkWithDetailed(result, "获取成功", c)
	}
}

// GetPromotionList 获取推广名单信息
func (s *BordApi) GetPromotionList(c *gin.Context) {
	ID := c.Query("id")
	if result, err := BordServiceApp.GetPromotionList(ID); err != nil {
		global.GVA_LOG.Error("获取失败!", zap.Error(err))
		response.FailWithMessage("获取失败!", c)
	} else {
		response.OkWithDetailed(result, "获取成功", c)
	}
}
